/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hpvas;

import boundary.MainWindow;
import dao.OwnerDAO;
import dao.PetDAO;
import dao.VeterinarianDAO;
import javax.persistence.Persistence;
import javax.swing.SwingUtilities;

/**
 *
 * @author Juan
 */
public class HPVAS {
    
    private static final MainWindow MAIN_WINDOW = new MainWindow();
    
    public static void loadOwners() {
        OwnerDAO ownerDAO = new OwnerDAO(Persistence.createEntityManagerFactory("HPVA"));
        MAIN_WINDOW.updateOwners(ownerDAO.findEntities());
    }
    
    public static void loadPets() {
        PetDAO petDAO = new PetDAO(Persistence.createEntityManagerFactory("HPVA"));
        MAIN_WINDOW.updatePets(petDAO.findEntities());
    }
    
    public static void loadVeterinarians() {
        VeterinarianDAO veterinarianDAO = new VeterinarianDAO(Persistence.createEntityManagerFactory("HPVA"));
        MAIN_WINDOW.updateVeterinarians(veterinarianDAO.findEntities());
    }
    
    public static void closeCurrentTab() {
        MAIN_WINDOW.closeCurrentTab();
    }
    
    public static void editEntity(Object entity) {
        MAIN_WINDOW.editEntity(entity);
    }
    
    public static void displayEntity(Object entity) {
        MAIN_WINDOW.displayEntity(entity);
    }
    
    public static void deleteEntity(Object entity) {
        MAIN_WINDOW.deleteEntity(entity);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        //<editor-fold defaultstate="collapsed" desc="Look and feel">
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                loadOwners();
                loadPets();
                loadVeterinarians();
                SwingUtilities.updateComponentTreeUI(MAIN_WINDOW);
                MAIN_WINDOW.pack();
                MAIN_WINDOW.setVisible(true);
            }
        });
    }
}
